package com.ygo.feihua;
import android.os.*;
import android.support.design.widget.*;
import android.support.v4.app.*;
import android.support.v4.view.*;
import android.view.*;
import com.ygo.feihua.*;
import java.util.*;
import android.widget.LinearLayout.*;
import android.app.Dialog;
import android.widget.*;
import com.ygo.feihua.fragment.*;

public class MessageQueryDialog extends DialogFragment
{
	List<Map<String,Object>> fg;;
	Find_tab_Adapter fAdapter;
	EditText dq_ed;
	Button dq_cx;
	
	
	public MessageQueryDialog(List<Map<String,Object>> fg){
		this.fg=fg;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState)
	{
		Dialog dialog = new Dialog(getActivity(), R.style.dialog);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // must be called before set content
		dialog.setContentView(R.layout.dialog_query);
		dialog.setCanceledOnTouchOutside(true);

		Display display = getActivity().getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		
		// 设置宽度为屏宽、靠近屏幕底部。
		Window window = dialog.getWindow();
		WindowManager.LayoutParams wlp = window.getAttributes();
	//	wlp.gravity = Gravity.BOTTOM;
		wlp.width = width * 75 / 100;
		window.setAttributes(wlp);
		return dialog;
		
	}
	
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View view = inflater.inflate(R.layout.dialog_query, container);
		
		TabLayout dq_tab=(TabLayout) view.findViewById(R.id.dq_tab);
		ViewPager dq_pag=(ViewPager) view.findViewById(R.id.dq_pag);
		dq_ed=(EditText) view.findViewById(R.id.dq_ed);
		dq_cx=(Button) view.findViewById(R.id.dq_cx);
		
	/*	dq_cx.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					String name=dq_ed.getText().toString().trim();
					
					for(Map<String,Object> map:fg){
						FragmentQueryList fq=(FragmentQueryList) map.get("fr");
						fq.messageQuery(name);
					}
					
					// TODO: Implement this method
				}
			});		*/
        //设置TabLayout的模式
        dq_tab.setTabMode(TabLayout.MODE_FIXED);
      	fAdapter = new Find_tab_Adapter(getChildFragmentManager());

        //viewpager加载adapter
        dq_pag.setAdapter(fAdapter);
		//缓存多个页面
		dq_pag.setOffscreenPageLimit(fg.size());
        //TabLayout加载viewpager
		dq_tab.setupWithViewPager(dq_pag);
		
		return view;
		
	}
	
	class Find_tab_Adapter extends FragmentPagerAdapter {
		public Find_tab_Adapter(FragmentManager fm) {
			super(fm);
		}


		@Override
		public Fragment getItem(int position) {
			return (Fragment)fg.get(position).get("fr");
		}

		@Override
		public int getCount() {
			return fg.size();
		}

		//此方法用来显示tab上的名字
		@Override
		public CharSequence getPageTitle(int position) {

			return (String)fg.get(position).get("title");
		}
	}
}
